<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function isObject(target) {
      return typeof target === 'object' && target !== 'null'
    }
    function cloneDeep(target) {
      const cache = new WeakMap()
      function run(target) {
        if(!isObject(target)) return target

        if(cache.has(target)) {
          return cache.get(target)
        }

        const result =  Array.isArray(target) ? [] : {}
        cache.set(target, result)
        for(let key in target) {
          if( target.hasOwnProperty(key) ) {
            result[key] = run(target[key])
          }
        }
        return result
      }
      return run(target)
    }
    const obj1 = {
      name:'wjp',
      age: 20,
      like: {
        type: 'sport',
        tag: 'aaa'
      }
    }
    obj1.like.own = obj1

    const obj2 = cloneDeep(obj1)
    obj1.like.type = 'ss'
    console.log(obj1)
    console.log(obj2)
  </script>
</body>
</html>